
        $(document).on('click','.test-api',function () {
            var _data = $(this).attr('data-role'),
                data = JSON.parse(_data);
            console.log(data)
            var path = data.route ? data.route.split(':') : '';
            var obj = data.rules
            var b = $.isEmptyObject(obj);
            if(!b){
                _is_params = true
                var _html = '';
                for(let key  in obj){
                    const tmp = obj[key]
                    const placeholder = tmp.range?tmp.desc + '('+tmp.range+')':tmp.desc
                    if(tmp.name === 'file'){
                        _html += `<div class="input-group margin-top-10">
              <span class="input-group-addon" id="basic-addon1">参数：${tmp.name}(file)：</span>
              <input type="file" class="form-control" name="${tmp.default}">
            </div>`
                    }else{
                        _html += `<div class="input-group margin-top-10">
              <span class="input-group-addon" id="basic-addon1">参数：${tmp.name}(${tmp.type})：</span>
              <input type="text" class="form-control" name="${tmp.name}" value="${tmp.default}" placeholder="${placeholder}">
            </div>`
                    }
                }
            }else{
                _html = '不需要参数'
                _is_params = false
            }
            _url = `${data.host}/${path[0]}`
            _method = `${path[1]}`
            _host = data.host
            var html = `<h4>请求地址：<span id="req-url">${data.host}${path[0]}</span>
            <button class="btn btn-info pull-right" id="request-api">发送请求</button></h4>
<h4>请求方式：<span class="req-method">${path[1]}</span></h4>
<h4>请求参数：</h4>
<form id="formData">
${_html}
</form>
<h4>返回结果：</h4>
<div class="json-view">
<i class="fa fa-spinner fa-pulse" id="loading"></i>
</div>`;
            layer.open({
                title: '接口测试',
                content: html,
                area: ['650px', '520px'],
                btn: ''
            });
        });

        $(document).on('click','#request-api',function () {
            const formData = new FormData($('#formData')[0])
            const __key = `${_host}_token`
            $.ajax({
                url: _url,
                type: _method,
                data: _is_params?formData:[],
                dataType: 'json',
                processData: false,
                contentType: false,
                beforeSend: function(xhr) {
                    const token =localStorage.getItem(__key) || ''
                    xhr.setRequestHeader("Authorization", 'Bearer ' + token)
                    $('#loading').show()
                },
                success:function (res) {
                    $('#loading').hide()
                    if(_url.indexOf('login')>-1){
                        localStorage.setItem(__key, res.data.access_token)
                    }
                    if(_url.indexOf('logout')>-1){
                        localStorage.setItem(__key, '')
                    }
                    if(_url.indexOf('refresh_token')>-1){
                        localStorage.setItem(__key, res.data.access_token)
                    }
                    $('.json-view').JSONView(res, {collapsed: true})
                },
                error:function (XMLHttpRequest, textStatus, errorThrown) {
                    console.log('a error: ' +  textStatus)
                }
            })
        });
